{include file="public_iframe:head" xmlns:H="http://www.w3.org/1999/xhtml"/}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>导航编辑</h5>
            <div class="ibox-tools" style="margin-top: -9px;">
                <a href="javascript:history.go(-1);" class="btn btn-primary"><i class="fa fa-arrow-left"></i> 返回</a>
            </div>
        </div>
        <div class="ibox-content">
            <form action="" method="post" enctype="multipart/form-data" id="brandForm" class="form-horizontal">
                <input type="hidden" name="id" value="{$da.id?$da.id:'';}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">导航名称</label>
                    <div class="col-sm-6">
                        <input type="text" name="name" id="name" value="{$da.name?$da.name:'';}" class="form-control" placeholder="导航名称" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">导航url</label>
                    <div class="col-sm-2">
                        <select class="form-control m-b" id="controller" onchange="get_act_list(this)">
                            <option value="">选择控制器</option>
                            {foreach name="planList" item="vo"}
                                <option value="{$vo}">{$vo}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="col-sm-2">
                        <select class="form-control m-b"  id="act_list">
                            <option value="">选择方法</option>
                            {foreach name="planList" item="vo"}
                                <option value="{$vo}">{$vo}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">状态</label>
                    <div class="col-sm-6">
                        <label class="checkbox-inline">
                            <input type="radio" name="status"  value="1"  {if condition="isset($da.is_display) and $da.is_display=='1'"} checked="checked"{/if}>启用
                        </label>
                        <label class="checkbox-inline">
                            <input type="radio" name="status"  value="0"  {if condition="isset($da.is_display) and $da.is_display=='0'"} checked="checked"{/if}>不启用
                        </label>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">排序</label>
                    <div class="col-sm-6">
                        <input type="text" name="num" id="num"  value="{$da.order_number?$da.order_number:'';}" class="form-control">(数字越大越排前)

                    </div>
                </div>
                <div class="hr-line-dashed"></div>

                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <!--<button class="btn btn-primary" type="submit">提交</button>-->
                        <!--href="JavaScript:void(0);" onclick="roleSubmit();"-->
                        <a href="JavaScript:void(0);" onclick="Submit();" class="btn btn-primary" id="submit">提交</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- End Panel Basic -->
</div>
<script>
    function get_act_list(obj){
        $.ajax({
            url: "{:url('Nav/ajax_get_action')}",
            type:'get',
            data: {'controller':$(obj).val()},
            dataType:'html',
            success:function(res){
                $('#act_list').empty().append(res);
            }
        });
    }

    function Submit(){
        var formData = new FormData();
        var id = $('input[name="id"]').val();
        var name = $('input[name="name"]').val();
        var num = $('input[name="num"]').val();
        var status = $('input[name="status"]:checked').val();
        var controller = $('select[name="controller"]:checked').val();
        var act_list = $('select[name="act_list"]:checked').val();
        formData.append('id',id);
        formData.append('name',name);
        formData.append('number',num);
        formData.append('status',status);
        formData.append('controller',controller);
        formData.append('action',act_list);

        $.ajax({
            url:"{:url('Nav/add')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function(result) {
                if(result.code == '0'){
                    parent.layer.alert(result.msg);
                }else{
                    parent.layer.msg(result.msg,{
                                icon:1,
                                time:1000,
                            },
                            function (index, item) {
                                location.href = result.url;
                            });
                }
            }
        });
    }
</script>

</body>

</html>